package design.pattern.Lu23BridgePattern;

/**
 * @program JavaBase
 * @description: 桥梁模式
 * @author: zhanglu
 * @create: 2020-05-19 21:19:00
 */
public class BridgePattern01 {

    public static void main(String[] args) {
        HouseCorp houseCorp = new HouseCorp(new House());
        houseCorp.makeMoney();

        ShanZaiCorp shanZaiCorp = new ShanZaiCorp(new IPod());
        shanZaiCorp.makeMoney();
    }

}

abstract class Product{
    //生产
    abstract void producted();
    //销售
    abstract void selled();
}

class House extends Product{

    @Override
    void producted() {
        System.out.println("生产房子...");
    }

    @Override
    void selled() {
        System.out.println("销售房子...");
    }
}

class IPod extends Product{

    @Override
    void producted() {
        System.out.println("生产pod...");
    }

    @Override
    void selled() {
        System.out.println("销售pod...");
    }
}

abstract class Corp{
    private Product product;
    public Corp(Product product){
        this.product = product;
    }
    public void makeMoney(){
        this.product.producted();
        this.product.selled();
    }
}

class HouseCorp extends Corp{

    public HouseCorp(Product product) {
        super(product);
    }

    @Override
    public void makeMoney() {
        super.makeMoney();
        System.out.println("房地产公司赚大钱了...");
    }
}

class ShanZaiCorp extends Corp{

    public ShanZaiCorp(Product product) {
        super(product);
    }

    @Override
    public void makeMoney() {
        super.makeMoney();
        System.out.println("山寨公司赚小钱了...");
    }
}

